function loadFile() {

    $("[ext-type='file']").each(function () {
        var id = $(this).attr("id");
        var value = $(this).attr("value");
        var v = JSON.parse(value);

        var disabled = $(this).attr("disabled");
        if (disabled == "disabled") {
            $(this).addClass("layui-btn-disabled");
            $(this).css("display", "none");
            $(this).parent().append("<div class=\"layui-upload-list\">\n" +
                "    <table class=\"layui-table\">\n" +
                "      <thead>\n" +
                "        <tr><th>文件名</th>\n" +
                "        <th>大小</th>\n" +
                "        <th>操作</th>\n" +
                "      </tr></thead>\n" +
                "      <tbody id=\"" + id + "List" + "\">\n" +
                "      </tbody>\n" +
                "    </table>\n" +
                "  </div>");

            var demoListView = $('#' + id + "List");
            v.forEach(function (item, index) {
                ActHttpRequest("/file/list?id=" + item, {}, function (data) {
                    var obj = data;
                    var tr = $(['<tr id="upload-' + index + '">'
                        , '<td>' + obj.fileOriginName + '</td>'
                        , '<td>' + obj.size / 1024.0 + '</td>'
                        , '<td>'
                        , '<input type="hidden" name=\"' + id + "Fid" + '\" id=\"' + item + '\" value=\"' + item + '\">'
                        , '<button type="button" class="layui-btn layui-btn-xs" onclick="getFile(\'' + item + '\')">打开</button>'
                        // ,'<button type="button" class="layui-btn layui-btn-xs layui-btn-danger" onclick="delFile(\''+item+'\', \''+index+'\' )"><i class="layui-icon">&#xe640;</i>删除</button>'
                        , '</td>'
                        , '</tr>'].join(''));
                    demoListView.append(tr);
                }, "get");
            });
        } else {
            $(this).parent().append("<div class=\"layui-upload-list\">\n" +
                "    <table class=\"layui-table\">\n" +
                "      <thead>\n" +
                "        <tr><th>文件名</th>\n" +
                "        <th>大小</th>\n" +
                "        <th>操作</th>\n" +
                "      </tr></thead>\n" +
                "      <tbody id=\"" + id + "List" + "\">\n" +
                "      </tbody>\n" +
                "    </table>\n" +
                "  </div>");

            var demoListView = $('#' + id + "List");
            v.forEach(function (item, index) {
                ActHttpRequest("/file/list?id=" + item, {}, function (data) {
                    var obj = data;
                    var tr = $(['<tr id="upload-' + index + '">'
                        , '<td>' + obj.fileOriginName + '</td>'
                        , '<td>' + obj.size / 1024.0 + '</td>'
                        , '<td>'
                        , '<input type="hidden" name=\"' + id + "Fid" + '\" id=\"' + item + '\" value=\"' + item + '\">'
                        , '<button type="button" class="layui-btn layui-btn-xs" onclick="getFile(\'' + item + '\')">打开</button>'
                        , '<button type="button" class="layui-btn layui-btn-xs layui-btn-danger" onclick="delFile(\'' + item + '\', \'' + index + '\' )"><i class="layui-icon">&#xe640;</i>删除</button>'
                        , '</td>'
                        , '</tr>'].join(''));
                    demoListView.append(tr);
                }, "get");
            });
        }


        $(this).removeAttr("onclick");//去除onclick事件
        var trt
        if (id == "designPdf" || id == "designCad") {
            upload.render({
                elem: this
                , url: '/file/upload'
                , accept: 'file' //普通文件
                , before: function (obj) {
                    var files = this.files = obj.pushFile();
                    //读取本地文件
                    obj.preview(function (index, file, result) {
                        trt = $(['<tr id="upload-' + index + '">'
                            , '<td>' + file.name + '</td>'
                            , '<td>' + (file.size / 1014).toFixed(1) + 'kb</td>'
                            , '<td>'
                            , '</td>'
                            , '</tr>'].join(''));

                    });
                }
                , done: function (res, index, upload) {
                    if (res.code != "200") {
                        layer.msg("非法文件名，请修改后再上传。", {icon: 2});
                    } else {
                        demoListView.append(trt);

                        var tr = demoListView.find('tr#upload-' + index)
                            , tds = tr.children();

                        layer.msg("上传成功");
                        var fid = res.id;
                        delete this.files[index]
                        if (tds.eq(2).children('button').length == 0) {
                            tds.eq(2).append("<input type=\"hidden\" name=\"" + id + "Fid" + "\" id=\"" + fid + "\" value=\"" + fid + "\"><button type='button' class='layui-btn layui-btn-xs' onclick='getFile(\"" + fid + "\")'>打开</button>"
                                + "<button type='button' class='layui-btn layui-btn-xs layui-btn-danger' onclick='delFile(\"" + fid + "\", \"" + index + "\" )'><i class='layui-icon'>&#xe640;</i>删除</button>");
                        } else {

                        }
                    }
                }
            });
        }else {
            upload.render({
                elem: this
                , url: '/file/upload'
                , accept: 'images' //图片文件
                ,acceptMime: 'image/jpg, image/png,image/gif,image/jpeg'
                ,exts:'jpg|png|gif|jpeg'
                , before: function (obj) {
                    var files = this.files = obj.pushFile();
                    //读取本地文件
                    obj.preview(function (index, file, result) {
                        trt = $(['<tr id="upload-' + index + '">'
                            , '<td>' + file.name + '</td>'
                            , '<td>' + (file.size / 1014).toFixed(1) + 'kb</td>'
                            , '<td>'
                            , '</td>'
                            , '</tr>'].join(''));

                    });
                }
                , done: function (res, index, upload) {
                    if (res.code != "200") {
                        layer.msg("非法文件名，请修改后再上传。", {icon: 2});
                    } else {
                        demoListView.append(trt);

                        var tr = demoListView.find('tr#upload-' + index)
                            , tds = tr.children();

                        layer.msg("上传成功");
                        var fid = res.id;
                        delete this.files[index]
                        if (tds.eq(2).children('button').length == 0) {
                            tds.eq(2).append("<input type=\"hidden\" name=\"" + id + "Fid" + "\" id=\"" + fid + "\" value=\"" + fid + "\"><button type='button' class='layui-btn layui-btn-xs' onclick='getFile(\"" + fid + "\")'>打开</button>"
                                + "<button type='button' class='layui-btn layui-btn-xs layui-btn-danger' onclick='delFile(\"" + fid + "\", \"" + index + "\" )'><i class='layui-icon'>&#xe640;</i>删除</button>");
                        } else {

                        }
                    }
                }
            });
        }
    });
}

//
// function loadImg(){
//
//     if(mainId == "" || mainId == undefined){
//         // formEventExecute("wfSystaskKey/saveTask.do", "保存", "1");
//         var uuid = UUID.prototype.createUUID().toLowerCase();
//         mainId = uuid;
//         $("#taskkeyId").val(mainId);
//     }
//
//     $("[ext-type='img']").each(function () {
//         var id = $(this).attr("id");
//         var value = $(this).attr("value");
//         var disabled = $(this).attr("disabled");
//         var v = JSON.parse(value);
//         if(disabled == "disabled"){
//             $(this).addClass("layui-btn-disabled");
//             $(this).css("display", "none");
//             if(v.length > 0){
//                 $(this).parent().append("<div style=\" width: 120px; height: 120px\">" +
//                     "<img style=\" width:  120px; height: 120px\" id=\""+ id+"img" +"\" src=\""+ getfile(v[0],'1')+"\">" +
//                     "<p id=\""+ id+"Text" +"\" ></p>" +
//                     "</div><input type=\"hidden\" id=\""+id+"Fid"+"\" value=\""+v[0] +"\">");
//             }
//         }else {
//             $(this).parent().append("<div style=\" width: 120px; height: 120px\">" +
//                 "<img style=\" width:  120px; height: 120px\" id=\""+ id+"img" +"\" src=\""+ getfile(v[0],'1')+"\">" +
//                 "<p id=\""+ id+"Text" +"\" ></p>" +
//                 "</div><input type=\"hidden\" id=\""+id+"Fid"+"\" value=\""+v[0] +"\">");
//         }
//
//         $(this).removeAttr("onclick");//去除onclick事件
//         upload.render({
//             elem: this//绑定元素
//             ,url: 'uploadFile/upload.do' //上传接口
//             ,data : {"BillId":mainId,"Path":"/流程/图片","base64":"true"}
//             ,before: function(obj){
//                 obj.preview(function(index, file, result){
//                     $('#'+id+"img").attr('src', result);
//                 });
//             }
//             ,done: function(res){
//                 if(res.OK=="error"){
//                     layer.msg(res.message, {icon: 2});
//                 }else{
//                     $('#'+id+"Fid").attr('value', res.fileID);
//                     layer.msg("上传成功");
//                 }
//             }
//             ,error: function(){
//                 //请求异常回调
//             }
//         });
//     });
// }

function delFile(id, index) {
    layer.confirm('确定要删除么？', {
            btn: ['确定', '取消'] //按钮
        }, function () {
            ActHttpRequest("/file/delete", {"id": id}, function (data) {
                layer.msg("删除成功");
                $('tr#upload-' + index).remove();
            });
        }, function () {
        }
    )

}

function getFile(id) {
    window.open("/file/download/" + id);

}